require "Common/define"
require "Logic/Config"
require "Common/functions"
---@class ChatManager
ChatManager = {};
local this = ChatManager;

local allChatMsgList = {}
local allChatMsgIdList = {};
local privateMsgLocalFile = "chatRecord.txt";       --默认工程根目录
local limitDataNum = 50;                               --
local saveLimitNum = 50;                               --限制数据本地存储条数
local passTime = 604800;                                    --过期时间七天 单位（秒）
local tbEmpty = {}
local marqueeList = {} --跑马灯数据
local msgNew = {}; --哪个聊天有新消息
local lastMsg = nil;--上一条消息
---@type table<number,number>
local isSendMsg = {};--是否可以发送消息，有cd时间 若值为 1 则处于cd中 若为nil则可以发送
--local marqueeData = {}
function ChatManager.init()
    this.emojiList = {}
    this.emojiTransferList = {}
end

function ChatManager.Destroy()
    allChatMsgList = {}
    allChatMsgIdList = {}
    table.clear(msgNew)
end
function ChatManager.AddSystemMsg(content)
    local time = HelperFunc.GetServerTime()
    local channel = Config.MsgChannel.System
    local msgData = {}
    msgData["id"] = this.CreateChatMsgId(channel, 1, time);
    msgData["Channel"] = channel;
    msgData["Message"] = content;
    msgData["head"] = 0;                 --自己的头像/modelId
    msgData["headFrame"] = 0;
    msgData["level"] = 0;               --自己的等级
    msgData["roleId"] = 1;             --自己的id
    msgData["roleName"] = "系统";         --自己的名字
    msgData["titleId"] = 0;           --勋章id
    msgData["unRead"] = true;
    msgData["lbs"] = ""
    msgData["time"] = time;
    msgData["favorLv"]=0;
    if not allChatMsgList[msgData.Channel] then
        allChatMsgList[msgData.Channel] = {}
    end
    this.InsertMsg(allChatMsgList[msgData.Channel], msgData)
    FireEvent(Config.EventType.Fresh_Chat, msgData);
end
function ChatManager.CreateChatMsgId(channel, roleId, time)
    return channel .. roleId .. time;
end
--聊天所有数据
function ChatManager.addChatMsg(msg, isLocal)
    --if not isLocal then
    -- print("===========ChatManager.addChatMsg============>"..msg.Message)
    --end
    --dataTable.PrintTable(msg);
    if (msg.time == nil) then
        msg.time = HelperFunc.GetServerTime(false)
    end
    local id = msg.id or this.CreateChatMsgId(msg.Channel, msg.roleId, msg.time);
    --logError("id:"..tostring(msg.id)..",createId:"..this.CreateChatMsgId(msg.Channel, msg.roleId, msg.time))
    if this.HasChatMsgById(id) or this.CheckContentSame(msg) then
        if not msg.unRead then
            this.SetRead(msg.Channel, id, msg.unRead)
        end
        return
    end
    local msgData = msg;
    msg.Message = logicMgr.ChatManager.FilterUBB("color",msg.Message);
    msg.Message = logicMgr.ChatManager.FilterUBB("size",msg.Message);
    if not isLocal then
        msgData = {}
        msgData["id"] = id;
        msgData["Channel"] = msg.Channel;
        msgData["Message"] = msg.Message;
        msgData["head"] = msg.head;                 --自己的头像/modelId
        msgData["headFrame"] = msg.headFrame;
        msgData["level"] = msg.level;               --自己的等级
        msgData["roleId"] = msg.roleId;             --自己的id
        msgData["roleName"] = msg.roleName;         --自己的名字
        msgData["titleId"] = msg.titleId;           --勋章id
        msgData["unionName"] = msg.unionName        --公会名
        msgData["unRead"] = msg.unRead;
        msgData["lbs"] = msg.lbs;
        msgData["time"] = msg.time;
        msgData["PlayerId"] = msg.PlayerId;         --私聊对象id
        msgData["PlayerName"] = msg.PlayerName;     --私聊对象名字
        msgData["PlayerHead"] = msg.PlayerHead;     --私聊对象头像/modelId
        msgData["serverId"] = msg.serverId
        msgData["favorLv"]=msg.favorLv
    end

    local channelMsg = allChatMsgList[msgData.Channel]
    if not channelMsg then
        channelMsg = {}
        allChatMsgList[msgData.Channel] = channelMsg
    end
    if msgData.Channel == Config.MsgChannel.Person then
        local playerId = logicMgr.HeroManager.GetRoleId()
        local chatId = 0
        if msg.roleId == playerId then
            chatId = msg.PlayerId
        elseif msg.PlayerId == playerId then
            chatId = msg.roleId
        end
        if chatId ~= 0 then
            if not channelMsg[1] then
                channelMsg[1] = {}
            end
            if not channelMsg[1][chatId] then
                channelMsg[1][chatId] = {}
            end
            this.InsertMsg(channelMsg[1][chatId], msgData)
            this.SaveToFile(isLocal)
        else
            if not channelMsg[2] then
                channelMsg[2] = {}
            end
            this.InsertMsg(channelMsg[2], msgData)
            this.SaveToFile(isLocal)
        end
    else
        this.InsertMsg(allChatMsgList[msgData.Channel], msgData)
        this.SaveToFile(isLocal)
    end

    --FireEvent(Config.EventType.Fresh_Chat, msgData);

    allChatMsgIdList[id] = true
    if not isLocal then
        FireEvent(Config.EventType.Fresh_Chat, msgData);
    end
    if msg.Channel == Config.MsgChannel.Guild and (isOpenUI(PanelResNames.UIGuildBattle) or isOpenUI(PanelResNames.UIGuildBattlePlus) or isOpenUI(PanelResNames.UIGuildBattlePlusFinal))then
        logicMgr.GuildBattleManager.addChatMsg(msg);
    end
    --log("msg.channel"..msg.Channel)
    --log("msg.Message"..msg.Message)
    if msg.Channel==Config.MsgChannel.InvasionTeam and isOpenUI(PanelNames.UIInvasionBattle)then
        log("InvasionBullet"..msg.Message)
        logicMgr.InvasionManager.addChatMsg(msg.Message)
    end

end
---@private
function ChatManager.SetRead(channel, id, isRead)

    local list = allChatMsgList[channel]
    if not list then
        return
    end
    if channel == Config.MsgChannel.Person then
        local privateList = list[1]
        if not privateList then
            return
        end
        for k, v in pairs(privateList) do
            for playerId, info in pairs(v) do
                if info.id == id then
                    info.unRead = isRead
                    return
                end
            end
        end
    else
        for _, info in pairs(list) do
            if info.id == id then
                info.unRead = isRead
                return
            end
        end
    end

end
function ChatManager.InsertMsg(tab, data)
    local count = #tab
    if count >= limitDataNum then
        table.remove(tab, 1)
    end
    table.insert(tab, data)
    if data.roleName ~= nil and data.unRead then
        if data.Channel == Config.MsgChannel.Person then
            if data.PlayerId == logicMgr.HeroManager.GetRoleId() then
                msgNew[data.Channel] = 1;
            end
        elseif data.Channel == Config.MsgChannel.Guild then
            msgNew[data.Channel] = 1;
            --msgNew[data.Channel] = 1;
        end

    end
end
function ChatManager.HasChatMsgById(id)
    return allChatMsgIdList[id]
end
function ChatManager.CheckContentSame(msg)
    local list = allChatMsgList[msg.Channel]
    if not list then return end
    if msg.Channel == Config.MsgChannel.Person then
        for k,v in pairs(list) do
            for k2,v2 in pairs(v) do
                local flag = this.CheckContentSame2(msg,v2)
                if flag then return true end
            end
        end
    else
        for k,v in pairs(list) do
            local flag = this.CheckContentSame2(msg,v)
            if flag then return true end
        end
    end
    return false
end
function ChatManager.CheckContentSame2(msg,msg1)
    local v = msg1
    if v.Message == msg.Message and v.roleId == msg.roleId and v.Channel == msg.Channel then
        if math.abs(v.time - msg.time) < 10000 then
            return true
        end
    end
    return false
end
---not person
function ChatManager.GetLastChatMsg(channel)
    local c = allChatMsgList[channel]
    if not c then
        return nil
    end
    return c[#c]
end
function ChatManager.ClearLBSMsg()
    local c = allChatMsgList[Config.MsgChannel.LBS]
    if c then
        table.clear(c)
    end
end
function ChatManager.ClearGuildRedPoint()
    msgNew[Config.MsgChannel.Guild] = nil;
    FireEvent(Config.EventType.Fresh_Chat_Red)
end
function ChatManager.SetMsgNewById(id, value)
    msgNew[id] = value;
end
function ChatManager.CheckMsgIdIsNew(id)
    if id == Config.MsgChannel.Guild and logicMgr.GuildManager.getUnionId() == 0 then
        return false;
    end
    if id == nil then
        return table.getn(msgNew) > 0;
    else
        return msgNew[id] == 1;
    end
end
--根据频道返回所有数据
function ChatManager.returnChatMsg(Channel, includeBlackList)
    --msgNew[Channel] = nil;
    local blacklist = this.GetShieldPlayers()
    local c = allChatMsgList[Channel]
    if not c then
        return tbEmpty
    end
    local tabMsg = {};
    if Channel == Config.MsgChannel.Person then
        for k, v in pairs(c) do
            if not logicMgr.FriendManager.IsInBlack(v.roleId) then
                for m, n in pairs(c[k]) do
                    for i = 1, #n do
                        table.insert(tabMsg, n[i]);
                    end
                end
            end
        end
    else
        local receiveNum=0
        for k, v in pairs(c) do
            if includeBlackList or not blacklist or not blacklist[v.roleId] or (v.playerId and not blacklist[v.playerId]) then
                local function  CheckInvasion(msgTbl)
                    if string.find(msgTbl["Message"],"<a href='"..Config.ChatLinkType.InvasionInvite.."'>.*</a>")~=nil then
                        if not FuncOpenManager.isOpen(Config.FuncOpenType.InvasionBattle)then
                            return true
                        end
                    end
                    return false
                end
                if not(CheckInvasion(v))then
                    if not logicMgr.FriendManager.IsInBlack(v.roleId) then
                        if Channel == Config.MsgChannel.Guild then
                            if v.unionName == logicMgr.GuildManager.getUnionName() then
                                table.insert(tabMsg, v)
                            end
                        else
                            table.insert(tabMsg, v);
                        end
                    end
                end
                receiveNum=receiveNum+1
            end
        end
        --MyLog("频道"..Channel.."收到消息数量与过滤后数量："..receiveNum.."  "..#tabMsg)
    end

    --[[    local tabMsg = {};
        for k,v in pairs(c) do
            if includeBlackList or not blacklist or not blacklist[v.roleId] or (v.playerId and not blacklist[v.playerId]) then
                table.insert(tabMsg,v);
            end
        end]]
    return tabMsg;
end
--返回私聊列表
--[[function ChatManager.returnAllPrivateList(includeBlackList)
    local tabAllPrivateMsg = {};
    tabAllPrivateMsg = this.returnChatMsg(Config.MsgChannel.Person,includeBlackList);
    --拿到对方的数据id等信息
    local tabAllOtherData = {};
    for k,v in pairs(tabAllPrivateMsg) do
        tabAllOtherData[v.roleId] = 1;
    end
    return tabAllOtherData;
end]]
--返回私聊玩家列表(如果需要排序，要单独处理)
function ChatManager.returnSelfPrivateList()
    local blacklist = this.GetShieldPlayers()
    local c = allChatMsgList[Config.MsgChannel.Person]
    if not c then
        return tbEmpty
    end
    local chatPlayers = c[1]
    if not chatPlayers then
        return tbEmpty
    end
    local tabAllOtherData = {};
    local myId = logicMgr.HeroManager.GetRoleId();
    for k, v in pairs(chatPlayers) do
        if not blacklist or not blacklist[k] then
            local otherData = {};
            otherData.PlayerId = k;
            if v[1].roleId == k then
                otherData.PlayerName = v[1].roleName;
                otherData.PlayerHead = v[1].head;
            else
                otherData.PlayerName = v[1].PlayerName;
                otherData.PlayerHead = v[1].PlayerHead;
            end
            local num = 0
            for k2, v2 in pairs(v) do
                if v2.unRead and v2.roleId ~= myId then
                    num = num + 1
                end
            end
            otherData.unReadNum = num;
            table.insert(tabAllOtherData, otherData);
        end
    end
    return tabAllOtherData
end
--通过私聊对象ID 返回 所有聊天内容（已按照时间排序）
function ChatManager.GetPrivateMsgByTwoPlayer(playerId1, playerId2)
    local tabPrivateMsg = {};
    local p = allChatMsgList[Config.MsgChannel.Person]
    if not p then
        return tbEmpty
    end
    local chatPlayers = p[1]
    if not chatPlayers then
        return tbEmpty
    end
    local privateMsg = chatPlayers[playerId1] or chatPlayers[playerId2]
    if not privateMsg then
        return tbEmpty
    end
    local blacklist = this.GetShieldPlayers()
    for k, v in pairs(privateMsg) do
        if not blacklist or not blacklist[v.roleId] or (v.playerId and not blacklist[v.playerId]) then
            table.insert(tabPrivateMsg, v);
        end
    end
    table.sort(tabPrivateMsg, this.sort);
    return tabPrivateMsg;
end
--通过私聊对象ID 返回 所有聊天内容（已按照时间排序）
function ChatManager.returnPrivateMsgById(PlayerId)
    local blacklist = this.GetShieldPlayers()
    local c = allChatMsgList[Config.MsgChannel.Person]
    if not c or not c[1] then
        return tbEmpty
    end
    return c[1][PlayerId]
    --[[local tabAllPrivateMsg = {};
    tabAllPrivateMsg = this.returnChatMsg(Config.MsgChannel.Person);
    local tabPrivateMsg = {};
    for i = 1, #tabAllPrivateMsg do
        if tabAllPrivateMsg[i].roleId == PlayerId or tabAllPrivateMsg[i].PlayerId == PlayerId then
            table.insert(tabPrivateMsg,tabAllPrivateMsg[i]);
        end
    end
    table.sort(tabPrivateMsg,this.sort);
    return tabPrivateMsg;]]
end

--通过私聊对象ID刷新消息已读
function ChatManager.refreshMsgRead(PlayerId)
    local tabPrivateMsg = this.returnPrivateMsgById(PlayerId);
    if not tabPrivateMsg then
        return
    end
    local myId = logicMgr.HeroManager.GetRoleId()
    for k, v in pairs(tabPrivateMsg) do
        if v.unRead and v.PlayerId == myId then
            v.unRead = false;
        end
    end
end
function ChatManager.HandlePrivateRed()
    local tab = logicMgr.ChatManager.returnSelfPrivateList()
    if not tab then
        --privateRedPoint.visible = false;
        return
    end
    local num = 0
    for k, v in pairs(tab) do
        num = num + v.unReadNum
    end
    if num > 0 then
        --privateRedPoint.visible = true;
        ChatManager.SetMsgNewById(Config.MsgChannel.Person, 1);
    else
        --privateRedPoint.visible = false;
        ChatManager.SetMsgNewById(Config.MsgChannel.Person, nil);
    end
    FireEvent(Config.EventType.Fresh_Chat_Red)
end
function ChatManager.HandleRedPoint(channel)
    if channel == Config.MsgChannel.Person then
        this.HandlePrivateRed()
    else
        this.refreshMsgReadByChannel(channel)
    end
end
function ChatManager.refreshMsgReadByChannel(channel)
    local list = allChatMsgList[channel]
    if not list then
        return
    end
    if channel ~= Config.MsgChannel.Person then
        for _, info in pairs(list) do
            info.unRead = false
        end
        this.SetMsgNewById(channel, nil)
        FireEvent(Config.EventType.Fresh_Chat_Red)
    else
        logError("MsgRead person player use [refreshMsgRead])")
    end
end
--按照时间排序
function ChatManager.sort(a, b)
    if a.time < b.time then
        return true;
    else
        return false;
    end
end
function ChatManager.SaveToFile(isLocal)
    if isLocal then return end
    if not isOpenUI(PanelNames.UIChatPanel) then
        this.setPrivateMsgInFile()
    end
end

function ChatManager.FilterUBB(ubb,str)
    local start = 0
    while (true) do
        local pos = string.find(str, "%["..ubb, start);
        if (not pos) then
            break
        end
        local pos2 = string.find(str, "]", pos + 1)
        if not pos2 then
            break
        end
        local temp = "%["..string.sub(str,pos+1,pos2)
        str = string.gsub(str,temp,"")

        pos = string.find(str, "%[/"..ubb, start);
        if (not pos) then
            break
        end
       pos2 = string.find(str, "]", pos + 1)
        if not pos2 then
            break
        end
        temp = "%["..string.sub(str,pos+1,pos2)
        str = string.gsub(str,temp,"")
    end
    str = this.FilterUBB2(str)
    return str
end
function ChatManager.FilterUBB2(str)
    local start = 0
    while (true) do
        local lowStr = string.lower(str)
        local pos = string.find(lowStr, "<font", start);
        if (not pos) then
            break
        end
        local pos2 = string.find(lowStr, ">", pos + 1)
        if not pos2 then
            break
        end
        local temp = string.sub(str,pos,pos2)
        str = string.gsub(str,temp,"")
    end
    return str
end

--本地存储 所有聊天 内容
function ChatManager.setPrivateMsgInFile()
    local tabAllMsgInFile = {};
    local person = this.returnChatMsg(Config.MsgChannel.Person, true);
    if person then
        for k, v in pairs(person) do
            table.insert(tabAllMsgInFile, v);
        end
    end

    --各个频道聊天数据（限存 limitDataNum 条）
    this.setDataInTab(tabAllMsgInFile, Config.MsgChannel.World);
    this.setDataInTab(tabAllMsgInFile, Config.MsgChannel.Server);
    this.setDataInTab(tabAllMsgInFile, Config.MsgChannel.Guild);
    local chatMsgStr = getJsonStr(tabAllMsgInFile);
    Util.SetPlayerPrefs(privateMsgLocalFile, chatMsgStr)
end

function ChatManager.setDataInTab(_list,Channel)
    local channelData = this.returnChatMsg(Channel, true);
    for i = 1, #channelData do
        if #channelData > saveLimitNum then
            table.remove(channelData, 1);
        else
            break ;
        end
    end
    for i = 1, #channelData do
        table.insert(_list, channelData[i]);
    end
end
local isFirstGetData = true
function ChatManager.LoadAllMsgFromFile()
    if isFirstGetData then
        isFirstGetData = false;
        local tabLocalPrivateMsg = ChatManager.getAllPrivateMsgFromFile();
        if tabLocalPrivateMsg ~= nil then
            for k, v in pairs(tabLocalPrivateMsg) do
                if v.serverId == Config.chatServerId or v.Channel ~= Config.MsgChannel.Server  then
                    this.addChatMsg(v, true);
                end
            end
        end
    end
end
--从 本地获取 所有聊天内容
function ChatManager.getAllPrivateMsgFromFile()
    local file = Util.GetPlayerPrefs(privateMsgLocalFile)
    if file ~= nil then
        local tabAllMsg = {};
        tabAllMsg = decodeJsonStrToTabel(file);
        return tabAllMsg
    else
        return nil;
    end

end
--屏蔽玩家
function ChatManager.SetShieldPlayer(playerId)
    local blackList = G.serverData.chatBlackList or {};
    blackList[playerId] = true;
    G.serverData.chatBlackList = blackList;
end
function ChatManager.GetShieldPlayers()
    return G.serverData.chatBlackList
end
local isLoadEmoji = false
function ChatManager.LoadEmoji()
    if isLoadEmoji then
        return this.emojiList
    end
    isLoadEmoji = true
    this.emojiList = decodeJsonStrToTabel(dataTable.getGlobalString(236))
    local parser = EmojiParser.inst
    parser:Clear()
    for k, v in pairs(this.emojiList) do
        parser:AddEmoji("Emoji", v)
        this.emojiTransferList["%[:" .. v .. "]"] = getLanguage("EmotionText_" .. v)
    end
    return this.emojiList
end
--emoji 表情名称
function ChatManager.GetEmojiName(index)
    local e = this.emojiList[index]
    if not e then
        return ""
    end
    return this.emojiTransferList["%[:"..e.."]"]
end
function ChatManager.TransferEmojiName(str)
    for k,v in pairs(this.emojiTransferList) do
    str = string.gsub(str,k,v)
    end
    return str
end
--表情名称转换为key
function ChatManager.TransferEmojiKey(str)
    for k,v in pairs(this.emojiTransferList) do
        str = string.gsub(str,v,k)
    end
    return str
end
--[[
    @desc: 敏感词汇检测
]]
function ChatManager.HasFilterBlockWord(text)
	local temp = filter_spec_chars(text)
    if temp == "" then
        return true,"**"
    end
	local blockword = dataTable.getDataTable("t_blockword")
    local p_s,p_e = nil, nil
    local has_black = false
	for k, v in ipairs(blockword) do
        p_s, p_e = string.find(temp, v.f_Value)--直接用find在遇到? &等单符号时会有问题
        if p_s then
            if p_e >= p_s then
                if string.sub(temp, p_s, p_e) == v.f_Value then
                    -- return true
                    temp = string.gsub(temp, v.f_Value, "**")
                    has_black = true
                end
            else
                if string.sub(temp, p_e, p_s) == v.f_Value then
                    -- return true
                    temp = string.gsub(temp, v.f_Value, "**")
                    has_black = true
                end
            end
        end
	end
	return has_black,temp
end


function ChatManager.AddMarquee(msg, chatSysMsg)
    --log
    --if not isSys then
    --local blockword = dataTable.getDataTable("t_blockword")
    -- for k, v in pairs(blockword) do
    --     msg = string.gsub(msg, v.f_Value, "**")
    -- end
    -- end
    if chatSysMsg == nil or chatSysMsg == "" then
        chatSysMsg = msg
    end
    table.insert(marqueeList, msg)
    --聊天系统
    logicMgr.ChatManager.AddSystemMsg(this.FilterColor(chatSysMsg, 200));
    if not this.showMarque then
        ChatManager.SendMarquee()
    end
end
function ChatManager.FilterColor(str, limitCount)
    local count = 0
    local start = 0
    while (true) do
        local pos = string.find(str, "%[", start);
        if (not pos) then
            break
        end
        local pos2 = string.find(str, "]", pos + 1)
        if not pos2 then
            break
        end
        count = count + pos2 - pos + 1
        start = pos2 + 1
    end
    return string.limitstr(str, limitCount + count), count;

end
function ChatManager.SendMarquee()
    this.showMarque = false
    if #marqueeList == 0 then
        FireEvent(Config.EventType.End_Marquee)
        return
    end
    local message = marqueeList[1]
    table.remove(marqueeList, 1)

    local str, colorCount = this.FilterColor(message, 200)

    local len = string.lenUtf8(str) - colorCount
    local descOriginX = 557 --文字初始位置
    local _end = 34 * len
    if UINotice then
        _end = UINotice.GetTextSize(str)
    end
    local descEndX = -(math.min(_end, 34 * len))  --文字终点位置
    local duration = math.abs(descEndX - descOriginX) / 150
    this.showMarque = true
    FireEvent(Config.EventType.Start_Marquee, str, descOriginX, descEndX, duration);
    this.marqueeTimerId = utimer.timeCall(ChatManager.SendMarquee, duration * 1000)
end
---------------------聊天@ta---------------------
function ChatManager.ChatPointer(msg, Channel)
    local playerName = msg.roleName;
    local message = msg.Message;
    local tabStr = string.split(message, " ");
    for i = 1, #tabStr do
        local a = string.find(tabStr[i], "@");
        if a ~= nil then
            local name = string.sub(tabStr[i], a + 1);
            if name == logicMgr.HeroManager.GetRoleName() then
                playerName = string.format("[color=#8A5731]%s[/color]", playerName);
                local channel = "";
                if Channel == Config.MsgChannel.World then
                    channel = "世界";
                elseif Channel == Config.MsgChannel.Guild then
                    channel = "公会";
                elseif Channel == Config.MsgChannel.Team then
                    channel = "队伍";
                elseif Channel == Config.MsgChannel.Person then
                    channel = "私聊";
                end
                local Channel = string.format("[color=#8A5731]%s[/color]", channel);

                UISysTips.AddMsg(playerName .. "在" .. Channel .. "中@了你一下");
                break ;
            end
        end
    end
end
------------ 打招呼 -----------
function ChatManager.addGetOneHello(playerId, playerName, emojiId)
    local data = {};
    data.playerId = playerId;
    data.playerName = playerName;
    data.emojiId = emojiId;
    if this.GetEmojiList == nil then
        this.GetEmojiList = {};
    end
    table.insert(this.GetEmojiList, data);
end

function ChatManager.getOneHello()
    if this.GetEmojiList == nil or #this.GetEmojiList == 0 then
        return nil;
    end
    return this.GetEmojiList[1];
end

function ChatManager.removeOneHello()
    if this.GetEmojiList ~= nil or #this.GetEmojiList > 0 then
        table.remove(this.GetEmojiList, 1);
    end
end

function ChatManager.addSendEmojiId(emojiId)
    this.sendEmojiId = emojiId;
end

function ChatManager.getSendEmojiId()
    return this.sendEmojiId;
end

function ChatManager.setSendEmojiTime(time)
    this.sendEmojiTime = time;
end

function ChatManager.getSendEmojiTime()
    return this.sendEmojiTime or 0;
end
---------------------------------------
------------------消息间隔处理-----------------------
function ChatManager.CheckMsg(chatType,text)
    if isSendMsg[chatType] ~= nil then
        --发言cd
        UISysTips.AddMsg(getLanguage("ChatProhibition1"));
        return false;
    end
    if text then
        if lastMsg == text then
            --重复发言CD
            UISysTips.AddMsg(getLanguage("ChatProhibition"));
            return false;
        end
        this.AddRepeatCutTime(text)
    end
    this.AddCutTime(chatType);
    return true;
end

function ChatManager.AddCutTime(chatType)
    --进入发言倒计时
    isSendMsg[chatType] = 1;
    local cdTime = G.dataTable["t_global"]["43"].f_int_value;
    if this.cdutimer then
        utimer.remove(this.cdutimer)
    end
    this.cdutimer = utimer.timeCall(function()
        isSendMsg[chatType] = nil;
    end, cdTime)
end

function ChatManager.AddRepeatCutTime(text)
    --进入重复发言倒计时
    lastMsg = text
    local cdTime = G.dataTable["t_global"]["315"].f_int_value;
    if this.RepeatUtimer then
        utimer.remove(this.RepeatUtimer)
    end
    this.RepeatUtimer = utimer.timeCall(function()
        lastMsg = nil;
    end, cdTime)
end
local _GMColor
function ChatManager.GMColor(textComp,str,defaultColor)
    if textComp == nil then return end
    if string.Contains(str,"GM") then
        if not _GMColor then
            _GMColor = Color.HexToColor("#f4e0ff")
        end
        textComp.color = _GMColor
    else
        textComp.color = defaultColor
    end
end

return ChatManager